package com.web;

import com.pojo.Result;
import com.pojo.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/users")
//@CrossOrigin
public class UserController {
    @GetMapping("/show")
    public Result show() {
        System.out.println("show...");
        return new Result(200, "查询成功", null);
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpServletRequest request) {
        Result result = new Result();

        if(user.getUsername().equals("tom") && user.getPassword().equals("123")) {
            //登录成功
            request.getSession().setAttribute("user", user);
            result.setCode(200);
            result.setMsg("登录成功");
        } else {
            //登录失败
            result.setCode(500);
            result.setMsg("用户名或者密码错误，登录失败");
        }

        return result;
    }
}
